package com.zhi.syc.data.http

import java.util.concurrent.CompletableFuture

class ASRequestManager(val url: String, val body: String, val taskId: String) {

    fun doPost() {
        if(this.url.isBlank() or this.body.isBlank()) return

        val task = ASPostAsyncTask(url = url, body = body, taskId = taskId)
        val supplier = CompletableFuture.supplyAsync(task)
        val allOfFuture = CompletableFuture.allOf(supplier)
        allOfFuture.thenRunAsync {
            try {
                val resObj = supplier.join()
                val code = resObj.optString("code")

                println("$taskId result obj: $resObj")
                println("$taskId result code: $code")
//                if (code.toInt() == 0) {
//                    println("$taskId result success ")
//                } else {
//                    println("$taskId result error ")
//                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}